package com.dxh.sqlSession;

import com.dxh.config.XMLConfigBuild;
import com.dxh.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author https://github.com/CoderXiaohui
 * @Description
 * @Date 2020-11-07 02:27
 */
public class SqlSessionFacetoryBuild {
    public SqlSessionFacetory build(InputStream in) throws DocumentException, PropertyVetoException {
        //1. 使用dom4j解析配置文件，将解析出来的内容封装到configuration中
        XMLConfigBuild xmlConfigBuild = new XMLConfigBuild();
        Configuration configuration = xmlConfigBuild.parseConfig(in);

        //2. 创建sqlSessionFactory对象 工厂类：生产sqlSession：会话对象，与数据库交互的增删改查都封装在sqlSession中
        DefaultSqlSessionFactory sqlSessionFacetory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFacetory;
    }

}
